home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / C / Applications / Python 1.3.3 / Python 133 SRC / Mac / Demo / sound / playaiff.py < prev   
Text File  |  1995-01-30  |  1KB  |  46 lines

  1. from Sound import *
  2. import Snd
  3.  
  4. import aifc, audioop
  5.  
  6. fn = 'f:just samples:2ndbeat.aif'
  7. af = aifc.open(fn, 'r')
  8. print af.getparams()
  9. print 'nframes  =', af.getnframes()
  10. print 'nchannels =', af.getnchannels()
  11. print 'framerate =', af.getframerate()
  12. nframes = min(af.getnframes(), 100000)
  13. frames = af.readframes(nframes)
  14. print 'len(frames) =', len(frames)
  15. print repr(frames[:100])
  16. frames = audioop.add(frames, '\x80'*len(frames), 1)
  17. print repr(frames[:100])
  18.  
  19. import struct
  20.  
  21. header1 = struct.pack('llhhllbbl',
  22.                       0,
  23.                       af.getnchannels(),
  24.                       af.getframerate(),0,
  25.                       0,
  26.                       0,
  27.                       0xFF,
  28.                       60,
  29.                       nframes)
  30. print repr(header1)
  31. header2 = struct.pack('llhlll', 0, 0, 0, 0, 0, 0)
  32. header3 = struct.pack('hhlll',
  33.                       af.getsampwidth()*8,
  34.                       0,
  35.                       0,
  36.                       0,
  37.                       0)
  38. print repr(header3)
  39. header = header1 + header2 + header3
  40.  
  41. buffer = header + frames
  42.  
  43. chan = Snd.SndNewChannel(5,0x00C0)
  44.  
  45. Snd.SndDoCommand(chan, (bufferCmd, 0, buffer), 0)
  46.